package cn.hzking.gjmall.webview;

import android.content.Context;
import android.content.Intent;
import android.webkit.JavascriptInterface;

import com.alibaba.fastjson.JSONObject;

import org.greenrobot.eventbus.EventBus;

import cn.hzking.gjmall.activitys.MainActivity;
import cn.hzking.gjmall.activitys.order.SureOrderActivity;
import cn.hzking.gjmall.activitys.second.WebGoodDetailActivity;

/**
 * Created by 傅令杰
 */

public class GjWebInterface {
    private final Context context;

    private GjWebInterface(Context context) {
        this.context = context;
    }

    public static GjWebInterface create(Context context) {
        return new GjWebInterface(context);
    }


    //前往首页
    @JavascriptInterface
    public void nativeToHome() {
        EventBus.getDefault().post("goHome");
        Intent intent = new Intent(context, MainActivity.class);
        context.startActivity(intent);
    }

    //分享
    @JavascriptInterface
    public void nativeGoodsShare(String json) {
        JSONObject parse = (JSONObject) JSONObject.parse(json);
        String imageurl = (String) parse.get("imageurl");
        String shareurl = (String) parse.get("shareurl");
        String title = (String) parse.get("title");
        String des = (String) parse.get("des");


    }

    //前往购物车
    @JavascriptInterface
    public void nativeCart() {
        EventBus.getDefault().post("goCar");
        Intent intent = new Intent(context, MainActivity.class);
        context.startActivity(intent);

    }

    //立即购买
    @JavascriptInterface
    public void nativeBuy( String skuIds, String skuNums) {
        Intent intent = new Intent(context, SureOrderActivity.class);
        intent.putExtra("itemSkuIds", skuIds);
        intent.putExtra("numbers", skuNums);
        //intent.putExtra("isBond", isBond);
        context.startActivity(intent);

    }

    //返回秒杀或者n元选列表页
    @JavascriptInterface
    public void backList() {
        ((WebGoodDetailActivity)context).finish();


    }


}
